package ua.javatr.android.smb;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DialogFragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

/**
 * Created by Вячеслав on 10.06.2014.
 */

@SuppressLint("NewApi")
public class DialogFragmentPhoneRecharge extends DialogFragment {


    private EditText etPhoneNumber, etPhoneSum;
    private Button btnNegative, btnPositive;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dialog_phone_recharge, null);
        getDialog().setTitle("Пополнение телефона");
        etPhoneNumber = (EditText) view.findViewById(R.id.etPhoneNumber);
        etPhoneSum = (EditText) view.findViewById(R.id.etPhoneSum);
        btnNegative = (Button) view.findViewById(R.id.btnNegative);
        btnPositive = (Button) view.findViewById(R.id.btnPositive);
        btnNegative.setOnClickListener(btnListener);
        btnPositive.setOnClickListener(btnListener);

        return view;
    }

    View.OnClickListener btnListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btnNegative:
                    getDialog().dismiss();
                    break;
                case R.id.btnPositive:
                    sensSMS(etPhoneNumber.getText().toString(),etPhoneSum.getText().toString());
                    break;
            }
        }
    };

    private void sensSMS(String number, String sum) {
        Uri uri = Uri.parse("smsto:"+number);
        Intent it = new Intent(Intent.ACTION_SENDTO,uri);
        it.putExtra("sms_body","PAY+"+sum);
        startActivity(it);
    }



}